/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2020. All rights reserved.
 */

package com.huawei.chengdu.meetingdemo.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPool {
    private static final ThreadPool INSTANCE = new ThreadPool();

    private final ExecutorService executor = new ThreadPoolExecutor(4, 4, 0L,
            TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());

    private ThreadPool() {
    }

    /**
     * 获取线程池的实例
     *
     * @return 线程池的实例
     */
    public static ThreadPool getInstance() {
        return INSTANCE;
    }

    /**
     * 提交任务
     *
     * @param task 任务
     * @return Future
     */
    public Future<Boolean> submit(Runnable task) {
        return executor.submit(task, true);
    }
}
